package com.milian.jdbc.test;

import java.sql.*;

/**
 * @Author milian
 * @Date 2021/8/19 0019 19:54
 */
public class jdbc_ResultSet {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // 注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        // 获取连接
        String url = "jdbc:mysql://127.0.0.1:3306/db10?useSSL=false";
        String username="root";
        String password="root";
        Connection conn = DriverManager.getConnection(url, username, password);

        String sql = "select * from student";
        Statement stmt = conn.createStatement();
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()){
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            System.out.println(id);
            System.out.println(name);

        }
        stmt.close();
        conn.close();


    }
}
